/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.kimstore.gui.staff;

import com.kimstore.bean.Staff;
import com.kimstore.factory.DaoFactory;

/**
 *
 * @author Administrator
 */
public class ManageCredentialsController {
    
    private ViewStaffController parentController;
    private ManageCredentialsWindow window;
    private Staff staff;
    
    public ManageCredentialsController(ViewStaffController parentController, Staff staff) {
        this.parentController = parentController;
        this.staff = staff;
    }
    
    public void displayWindow(){
        window = new ManageCredentialsWindow(this, staff);
        window.populateWindow();
        window.showWindow();
    }
    
    public void fromWindow(){
        DaoFactory.getInstance().getStaffDao().saveOrUpdate(staff);
        window.dispose();
    }

    public boolean isUsernameTaken(String text) {
        if(staff.getUser().getUsername().equals(text)) return false;
        
        return DaoFactory.getInstance().getUserDao().existsUsername(text);
    }
    
}
